<template>
  <div>
    <h1>飞机基本信息</h1>
    <div id="planeTable">
      <table-componet :table-data="tableData" :table-label="tableLabel" :config="config"></table-componet>
    </div>
  </div>
</template>

<script>
import TableComponet from "../../components/TableComponet";
export default {
  name: "planeInfo",
  components: {
    TableComponet
  },
  methods: {
    getPlaneInfo() {
      this.config.loading = true;
      // 搜索时，页码需要设置为1，才能正确返回数据，因为数据是从第一页开始返回的
      name ? (this.config.page = 1) : "";
      this.$http
        .get("/api/user/getUser", {
          params: {
            page: this.config.page,
            name
          }
        })
        .then(res => {
          this.tableData = res.data.list.map(item => {
            item.sexLabel = item.sex === 0 ? "女" : "男";
            return item;
          });
          console.log(this.tableData);
          this.config.total = res.data.count;
          this.config.loading = false;
        });
    }
  },
  data() {
    return {
      tableData: [],
      tableLabel: [
        {
          prop: "name",
          label: "姓名"
        },
        {
          prop: "age",
          label: "年龄"
        },
        {
          prop: "sexLabel",
          label: "性别"
        },
        {
          prop: "birth",
          label: "出生日期",
          width: 200
        },
        {
          prop: "addr",
          label: "地址",
          width: 320
        }
      ],
      config: {
        page: 1,
        total: 30,
        loading: false
      }
    };
  },
  created() {
    this.getPlaneInfo();
  }
};
</script>

<style lang="scss" scoped>
#planeTable {
  height: 400px;
}
</style>
